﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace MvvmEx.Converter
{
    /// <summary>
    /// bool to bool Converter
    /// </summary>
    public class BoolToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool realValue = Boolean.Parse(value.ToString());

            bool parameterValue = Boolean.Parse(parameter.ToString());

            if (realValue == parameterValue)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool realValue = Boolean.Parse(value.ToString());

            bool parameterValue = Boolean.Parse(parameter.ToString());

            if (realValue)
            {
                if (realValue == parameterValue)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return Binding.DoNothing;
            }
        }
    }
}